<?php
/**
 * Created by PhpStorm.
 * User: medivh
 * Date: 15-6-28
 * Time: 下午6:36
 */
namespace DaChongQing\Controller;
use Think\Controller;
class NewsAdminController extends Controller{
    public function IsSignIn(){
        if(session("UserId") == "" || session("UserId") == null || session("UserType") != "edit"){
            $this->error("对不起，请先登录，否则，你将不能进行操作！",U('NewsAdmin/SignIn'));
        }
    }
    public function index(){
        self::IsSignIn();
//        echo session("UserId");
//        echo session("UserType");
        $this->display();
    }
    public function IsOk(){
        $UserInfo = array(
            "userid" => session("UserId"),
            "userkey" => sha1(md5(I("key"))),
            "type" => "edit"
        );
        if($UserInfo["userid"] == null || $UserInfo["userkey"] == null){
            $this->ajaxReturn("请输入信息再提交…………","EVAL");
        }else{
            $result = M("news_admin")->where($UserInfo)->find();
            if($result["userid"] == null || $result["userkey"] == null){
                $this->ajaxReturn("对不起，不存在的账户","EVAL");
            }else{
                $this->ajaxReturn("1","EVAL");
            }
        }
    }
    public function SignIn(){
        if(!IS_AJAX){
            $this->display();
        }else{
            $UserInfo = array(
                "userid" => I("username"),
                "userkey" => sha1(md5(I("userkey"))),
                "type" => "edit"
            );
            if($UserInfo["userid"] == null || $UserInfo["userkey"] == null){
                $this->ajaxReturn("请输入信息再提交…………","EVAL");
            }else{
                $result = M("news_admin")->where($UserInfo)->find();
                if($result["userid"] == null || $result["userkey"] == null){
                    $this->ajaxReturn("对不起，不存在的账户","EVAL");
                }else{
                    session("UserId",$result["userid"]);
                    session("UserType",$result["type"]);
                    $this->ajaxReturn("1","EVAL");
                }
            }
        }
    }
    public function pass(){
        echo sha1(md5("weirong1"))."<hr style='border:5px solid #333'>";
        echo sha1(md5("weirong2"))."<hr style='border:5px solid #333'>";
        echo sha1(md5("weirong3"))."<hr style='border:5px solid #333'>";
        echo sha1(md5("weirong4"))."<hr style='border:5px solid #333'>";
        echo sha1(md5("weirong5"))."<hr style='border:5px solid #333'>";
    }
    public function js(){
        echo JsapiTicket();
    }
}